import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: JSON.parse(localStorage.getItem("userInfo")),
    token: JSON.parse(localStorage.getItem("token")),
  },
  mutations: {
    setUserInfo (state, value) {
      if (value === null || value === undefined) {
        this.state.userInfo = null
        localStorage.removeItem("userInfo")
      } else {
        localStorage.setItem("userInfo", JSON.stringify(value))
        this.state.userInfo = value
      }
    },
    setToken (state, value) {
      if (value === null || value === undefined) {
        localStorage.removeItem("token")
        this.state.token = null
      } else {
        localStorage.setItem("token", JSON.stringify(value))
        this.state.token = value
      }

    }
  },
  actions: {

  }
})
